using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FieldbookWin.User;
using FieldbookWin.FieldbookServices;

namespace FieldbookWin
{
    public partial class MainForm : Form
    {
        private FieldbookServices.FieldbookService fbService;
        private FieldbookServices.Appuser loggedUser;

        private LoginForm loginForm;
        private RegisterUserForm registerUserForm;
        private FieldsOverviewForm filedsOverview;


        public MainForm()
        {
            InitializeComponent();
            fbService = new FieldbookWin.FieldbookServices.FieldbookService();
        }


        public FieldbookServices.FieldbookService FbService
        {
            get { return fbService; }
        }

        public FieldbookServices.Appuser LoggedUser
        {
            get { return loggedUser; }
            set { loggedUser = value; }
        }

        public LoginForm LoginForm
        {
            get
            {
                if (this.loginForm == null)
                {
                    this.loginForm = new LoginForm();
                    this.loginForm.MdiParent = this;
                }
                return loginForm;
            }
        }
        public RegisterUserForm RegisterUserForm
        {
            get
            {
                if (this.registerUserForm == null)
                {
                    this.registerUserForm = new RegisterUserForm();
                    this.registerUserForm.MdiParent = this;
                }
                return registerUserForm;
            }
        }

        public FieldsOverviewForm FiledsOverview
        {
            get 
            {
                if (this.filedsOverview == null)
                {
                    this.filedsOverview = new FieldsOverviewForm();
                    this.filedsOverview.MdiParent = this;
                }
                return filedsOverview; 
            }
        }


        private void MainForm_Load(object sender, EventArgs e)
        {
            this.LoginForm.Show();
        }

        private void fieldsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.loggedUser != null)
            {
                Field[] fields = this.FbService.LoadHouseHoldFields((long)this.loggedUser.Userid);
                ShowListFieldsForm();
            }
            else
            {
                this.LoginForm.Show();
            }
        }

        public void ShowListFieldsForm()
        {
            this.FiledsOverview.Show();
        }
    }
}